<template>
	<view class="wrap">
		<uni-forms-item label="类型" required>
			<uni-data-select v-model="type" :localdata="range"></uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="描述" required>
			<uni-easyinput type="textarea" maxlength="1000" v-model="message" placeholder="请详细描述您遇到的问题（不超过1000字）" />
		</uni-forms-item>
		<view class="baocun row j-center a-center" @click="preserve">
			提交
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { ref } from 'vue'
	import { request } from '@/utils'
	const type = ref('')
	const message = ref('')
	const range = ref([
		{
			value: '问题',
			text: '问题'
		},
		{
			value: '建议',
			text: '建议'
		}
	])
	const preserve = async () => {
		if(!type.value) {
			uni.showToast({
				title: '类型不能为空',
				icon: 'error'
			})
			return
		}
		if(!message.value) {
			uni.showToast({
				title: '描述不能为空',
				icon: 'error'
			})
			return
		}
		const res:any = await request('/api/v1/addAdvice?permission=feedBack', {type: type.value, message: message.value}, 'POST')
		if(res.code === 1000) {
			uni.showToast({
				title: '提交成功'
			})
			setTimeout(() => {
				uni.navigateBack()
			}, 500)
		} else {
			uni.showToast({
				title: res.message,
				icon: 'error'
			})
		}
	}
</script>

<style scoped lang="scss">
	::v-deep .uni-easyinput__content-textarea {
		min-height: 300rpx;
	}
	.wrap {
		padding: 30rpx 24rpx;
		background-color: #F6F6F6;
		padding-bottom: 40rpx;
		min-height: 100vh;
		position: relative;
		.baocun {
			position: absolute;
			bottom: 100rpx;
			// width: 100%;
			left: 50rpx;
			right: 50rpx;
			height: 88rpx;
			background-color: #3665FF;
			border-radius: 200rpx;
			color: #fff;
			font-size: 34rpx;
			margin-top: 50rpx;
		}
	}
</style>